package com.neuedu.jdbc.annotation;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Runner {


    public static void main(String[] args) throws NoSuchFieldException {

        Class clazz = Menu.class;

        String columnName = "menu_id";
        Field menuId = null;
        try{
            menuId = clazz.getDeclaredField(columnName);
        }catch (Exception e ){
            //遍历属性,查找那个属性有 注解  menu_id
            Field[] declaredFields = clazz.getDeclaredFields();
            for (Field declaredField : declaredFields) {
                ColumnMapping annotation = declaredField.getAnnotation(ColumnMapping.class);
                if(annotation != null && annotation.value().equals(columnName) ){
                    menuId= declaredField;
                    break;
                }
            }

        }
        System.out.println("menuId = " + menuId);

    }



}
